package HLLib.userControl;

import javax.microedition.lcdui.TextField;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLLibObject;
import HLLib.base.HLICallback;
import HLLib.base.HLString;
import HLLib.http.IEvent;
import HLLib.userControl.defalut.HLScreenTextFiled;

public class HLTextField extends HLLibObject implements HLICallback {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_USERCONTROL, HLClassManager_H.LIB_CLASS_USERCONTROL_TextField);
    }

    private static HLScreenTextFiled tf;

    public static void ShowTextField(int keyboardType, boolean secureTextEntry, HLString placeholder) {
        tf = new HLScreenTextFiled("", "", placeholder == null ? "" : placeholder.string, secureTextEntry ? TextField.PASSWORD : TextField.ANY);
        tf.eventOver = new IEvent() {
            public void Action(Object sender, Object data) {
                curRun.CallbackSuccess(CALLBACK_TEXTFIELD_DONE, new HLString(tf.GetString()));
                tf = null;
            }
        };
        tf.eventReturn = new IEvent() {
            public void Action(Object sender, Object data) {
                curRun.CallbackSuccess(CALLBACK_TEXTFIELD_CANCEL, null);
                tf = null;
            }
        };
        tf.show();
    }

    public static void ShowTextFieldEX(int keyboardType, boolean secureTextEntry, HLString placeholder, int charCount) {
        tf = new HLScreenTextFiled("", "", placeholder == null ? "" : placeholder.string, secureTextEntry ? TextField.PASSWORD : TextField.ANY, charCount);
        tf.eventOver = new IEvent() {
            public void Action(Object sender, Object data) {
                curRun.CallbackSuccess(CALLBACK_TEXTFIELD_DONE, new HLString(tf.GetString()));
                tf = null;
            }
        };
        tf.eventReturn = new IEvent() {
            public void Action(Object sender, Object data) {
                curRun.CallbackSuccess(CALLBACK_TEXTFIELD_CANCEL, null);
                tf = null;
            }
        };
        tf.show();
    }
}
